package org.elzat.healthboxgatewayapp.credentials;

import org.springframework.security.core.GrantedAuthority;

public enum HealthBoxAuthority implements GrantedAuthority {

    /************************用户相关****************************/
    // 用户信息读权限
    // SYSTEM_ADMIN, ORGAN_ADMIN
    USER_READ("user:read"),
    // 用户信息写权限：封锁、解封用户、注册新的管理员
    // SYSTEM_ADMIN
    USER_WRITE("user:write"),
    // 预约信息读权限
    // SYSTEM_ADMIN, ORGAN_ADMIN, USER

    /************************预约相关****************************/
    APPOINTMENT_READ("appointment:read"),
    // 预约信息写(进行预约)权限
    // USER
    APPOINTMENT_MAKE("appointment:make"),
    // 预约信息创建权限
    // ORGAN_ADMIN
    APPOINTMENT_CREATE("appointment:create"),
    // 核酸机构读权限
    // SYSTEM_ADMIN, ORGAN_ADMIN, USER

    /************************机构相关****************************/
    ORGAN_READ("organ:read"),
    // 核酸机构写(注册、封锁、解封等)权限
    // SYSTEM_ADMIN
    ORGAN_WRITE("organ:write"),
    // 核酸结果读权限
    // SYSTEM_ADMIN, ORGAN_ADMIN, USER

    /************************核酸结果相关****************************/
    RESULT_READ("result:read"),
    // 核酸结果写权限
    // ORGAN_ADMIN
    RESULT_WRITE("result:write"),
    // 报备通告信息的读权限
    // USER, SYSTEM_ADMIN, ORGAN_ADMIN

    /************************通告相关****************************/
    NOTIFICATION_READ("notification:read"),
    // 报备通告信息相关地理位置的写权限
    // SYSTEM_ADMIN, ORGAN_ADMIN
    NOTIFICATION_WRITE("notification:write"),
    // 更新用户位置相关信息
    // USER
    NOTIFICATION_UPDATE("notification:update"),

    RISK_READ("risk:read"),
    RISK_WRITE("risk:write"),
    HEALTH_READ("health:read"),
    HEALTH_WRITE("health:write"),
    REPORT_READ("report:read"),
    REPORT_WRITE("report:write"),

    /************************核酸机构公告相关****************************/
    // 核酸机构公告信息写权限
    ANNOUNCEMENT_READ("announcement:read"),
    // 核酸机构公告信息读权限
    ANNOUNCEMENT_WRITE("announcement:write"),


    ROLE_USER("role:user"),
    ROLE_SYSTEM_ADMIN("role:system_admin"),
    ROLE_ORGAN_ADMIN("role:organ_admin");

    private final String authority;
    HealthBoxAuthority(String authority) {
        this.authority = authority;
    }

    @Override
    public String getAuthority() {
        return authority;
    }

    public static HealthBoxAuthority get(HealthBoxUserRole role) {
        switch (role) {
            case ORGAN_ADMIN: return ROLE_ORGAN_ADMIN;
            case SYSTEM_ADMIN: return ROLE_SYSTEM_ADMIN;
            case USER: return ROLE_USER;
        }
        return null;
    }
}
